import Vue from 'vue'
// import moment from 'moment'
import { pageList,pageDelete } from '@/api/api';
export const Mixin = {
    data(){
      return{

      }
    },
    created(){//初始化
       this.pages.page = Number(this.$route.query.page||1);
       this.searchQuery(this.pages);
    },
   methods:{
    add(){//新增
        let query = {
          page:this.pages.page,
          id:'',
          disabled:false
        }
        if(!!this.addEditPath){
            this.$router.push({path:this.addEditPath,query})
        }
        
      },
      edit(v){//编辑
        let query = {
            page:this.pages.page,
            id:v.id,
            disabled:false
          }
          this.$router.push({path:this.addEditPath,query})
      },
      handleLook(v){//查看
        let query = {
            page:this.pages.page,
            id:v.id,
            disabled:true
          }
          this.$router.push({path:this.addEditPath,query})
      },
      handleDelete(v){//删除
        let that = this;
        this.$confirm('是否删除选中的数据？', '删除提示！', {
          distinguishCancelAndClose: true,
          confirmButtonText: '确定',
          cancelButtonText: '取消删除'
        })
          .then(() => {
                 console.log(1)
                 let data ={id:v.id}
            if(that.pageUrl&&that.pageUrl.del){
              pageDelete(that.pageUrl.del,data).then(res=>{
            
               
                if(res.code==0){
                  that.$message({
                    type: 'success',
                    message: '删除成功'
                  });
                  that.searchQuery(that.pages);
                }else{
                  that.$ErrorToast(res);
                }
              })
          }
          })
          .catch(action => {
          
          });
        
      },
      searchQuery(data){
        let that = this;
        that.loading = true;
        if(that.pageUrl&&that.pageUrl.list){
            pageList(that.pageUrl.list,data).then(res=>{
              if(res.code==0){
                that.lists = res.data.list;
                that.total = Number(res.data.total);
              }else{
                that.$ErrorToast(res);
              }
            
            })
        }
        this.loading = false;
      },
      search(){//搜索
        this.pages.page = 1;
        this.searchQuery(this.pages);
      },
     
   }
}